import collections


class Solution:
    def smallestSubsequence(self, text: str) -> str:
        counter = collections.Counter(text)
        stack = []
        for s in text:
            counter[s] -= 1
            if s in set(stack):
                continue
            while stack and stack[-1] > s:
                if counter[stack[-1]] == 0:
                    break
                stack.pop()
            stack.append(s)
        return "".join(stack)
